<?php

namespace App\Models;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class FeeConfig
 * @package App\Models
 * @version May 24, 2018, 10:49 am CST
 *
 * @property string park_code
 * @property int rule
 * @property int rule_type
 * @property int car_type
 * @property int period_time
 * @property int free_time
 * @property int start_time
 * @property int start_money
 * @property int adders_time
 * @property int adders_money
 * @property int period_top
 */
class FeeConfig extends Model
{
    use SoftDeletes;

    public $table = 'fee_config';
    

    protected $dates = ['deleted_at'];


    public $fillable = [
        'park_code',
        'rule',
        'rule_type',
        'car_type',
        'period_time',
        'free_time',
        'start_time',
        'start_money',
        'adders_time',
        'adders_money',
        'period_top'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'park_code' => 'string'
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'park_code' => 'required'
    ];

    /**
     * 将资源转换成数组。
     *
     * @param  \Illuminate\Http\Request
     * @return array
     */
    public function toArray()
    {
        if(!is_null($this->park_code)) {
            $mergeArray['park_name'] = ParkInfo::where("park_code",$this->park_code)->value("parking_name");
        }

        return array_merge(parent::toArray(), $mergeArray);
    }

    
}
